#!/bin/bash

set -eu

source "$(dirname $0)/../../utils/common"
# Simple end-to-end test for an application's curl

function strip_http_header {
    sed 's/^Date:.*/Date:/' | sed 's/^Server:.*/Server:/'
}

function setup {
    /usr/bin/env python2.7 -m SimpleHTTPServer 8004 >/dev/null 2>&1 &
    httpserver="$!"

    tc class add dev tap0 parent 1: classid 1:3 htb rate 100mbit
    tc filter add dev tap0 parent 1: protocol ip prio 1 u32 flowid 1:3 match ip sport 8004 0xffff
    tc filter add dev tap0 parent 1: protocol ip prio 1 u32 flowid 1:3 match ip dport 8004 0xffff
    tc qdisc add dev tap0 parent 1:3 netem loss 25%

    sleep 5
}

function teardown_suite {
    kill "$httpserver"
}

trap teardown_suite EXIT ERR
setup
